/*
 * This script is executed inside the EDT, so be sure to
 * call long running code in another thread.
 *
 * You have the following options
 * - SwingBuilder.doOutside { // your code  }
 * - Thread.start { // your code }
 * - SwingXBuilder.withWorker( start: true ) {
 *      onInit { // initialization (optional, runs in current thread) }
 *      work { // your code }
 *      onDone { // finish (runs inside EDT) }
 *   }
 *
 * You have the following options to run code again inside EDT
 * - SwingBuilder.doLater { // your code }
 * - SwingBuilder.edt { // your code }
 * - SwingUtilities.invokeLater { // your code }
 */

import groovy.swing.SwingBuilder
import griffon.util.GriffonPlatformHelper
import net.sshiffon.logging.LoggingExceptionHandler

def handleUncaught = true
def doSplash = true

//bug workaround for groovy v1.5 -> v1.7
javax.swing.JTable.metaClass.removeProppertyChangeListener = {  name, listener ->
	return removePropertyChangeListener(name,listener)
}


GriffonPlatformHelper.tweakForNativePlatform(app)
SwingBuilder.lookAndFeel('mac', 'nimbus', 'gtk', ['metal', [boldFonts: false]])

//org.apache.log4j.BasicConfigurator.configure()


def log4jprops = [
        log4j : [
            appender: [
                stdout : 'org.apache.log4j.ConsoleAppender',
                'stdout.layout':'org.apache.log4j.PatternLayout',
                'stdout.layout.ConversionPattern':'%-5p [%t]: [%r] %c{2} %m%n',
                errors : 'org.apache.log4j.FileAppender',
                'errors.layout':'org.apache.log4j.PatternLayout',
                'errors.layout.ConversionPattern':'%-5p [%t]: [%r] %c{2} %m%n',
                'errors.File':'stacktrace.log'],
            rootLogger:'info,stdout',
            logger : ['net.sshiffon': 'debug'],
            additivity: [StackTrace:false]
            ] ] as java.util.Properties

            
org.apache.log4j.PropertyConfigurator.configure(new ConfigSlurper().parse(log4jprops).toProperties())

if(handleUncaught)
{
    Thread.setDefaultUncaughtExceptionHandler(new LoggingExceptionHandler());
    Thread.currentThread().setUncaughtExceptionHandler(new LoggingExceptionHandler());
    System.setProperty("sun.awt.exception.handler", LoggingExceptionHandler.class.getName());
}

if(doSplash)
{

    // Setting a splash image
    SplashScreen.getInstance().setImage(this.class.getResource("sshiffon01.jpg"))
    // Setting Status Text
    SplashScreen.getInstance().showStatus("SSHiffon is beginning ...")
    SplashScreen.getInstance().splash()
    SplashScreen.getInstance().waitForSplash()
    
}